﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Car_Rental;

namespace Data.Car_Rental
{
    public class ShopRepository : Car_RentalRepositoryBase, IShopRepository
    {
        #region IShopRepository 成员

        public Entity.PagedList<Entity.Car_Rental.Shop> GetShopByAreaID(Entity.VPredication vp, Entity.PagingParam pp)
        {
            var linq = from data in this.GetModel()
                       join data2 in new AreaRepository().GetModel() on data.AreaID equals data2.CodeID
                       select new Shop_Ext
                       {
                           AreaID = data.AreaID,
                           CreateDate = data.CreateDate,
                           Info = data.Info,
                           ShopID = data.ShopID,
                           ShopName = data.ShopName,
                           Status = data.Status,
                           UpdateDate = data.UpdateDate,
                           Area_Extend = data2,
                       };
            Area area = null;
            if (vp.ContainsKey("area"))
                area = new AreaRepository().GetAddressByName(vp["area"].ToString(), Convert.ToInt32(vp["length"]));
            if (area != null)
                linq = linq.Where(i => i.AreaID == area.CodeID);
            return new Entity.PagedList<Shop>(linq, pp.PageIndex, pp.PageSize);
        }

        #endregion

        #region IRepository<Shop> 成员

        public void Update(Entity.Car_Rental.Shop entity)
        {
            base.UpdateEntity(entity);
        }

        public void Update(IList<Entity.Car_Rental.Shop> list)
        {
            base.UpdateEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public void Insert(Entity.Car_Rental.Shop entity)
        {
            base.InsertEntity(entity);
        }

        public void Insert(IList<Entity.Car_Rental.Shop> list)
        {
            base.InsertEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public Entity.Car_Rental.Shop InsertGetIDENTITY(Entity.Car_Rental.Shop entity)
        {
            base.InsertEntity(entity);
            return this.Find(entity.PrimaryKey);
        }

        public void Delete(Entity.Car_Rental.Shop entity)
        {
            base.DeleteEntity(entity);
        }

        public void Delete(IList<Entity.Car_Rental.Shop> list)
        {
            base.DeleteEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public IQueryable<Entity.Car_Rental.Shop> GetModel()
        {
            return base.GetEntities<Shop>();
        }

        public Entity.Car_Rental.Shop Find(params object[] keyValues)
        {
            return base.Find<Shop>(keyValues);
        }

        #endregion
    }
}
